<!--
 * @Description: 大前端学习
 * @Version: H5
 * @Author: Ajax
 * @Date: 2020-04-22 21:10:07
 * @LastEditors: Ajax
 * @LastEditTime: 2020-04-22 21:59:08
 -->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>开关灯</title>
</head>

<body>
  <button id="btn">隐藏</button><br>
  <img src="images/img04.jpg" alt="" width="400px">
</body>
<script>
  var btn = document.querySelector('#btn');
  var img = document.querySelector('img');
  btn.onclick = function () {
    if (btn.innerHTML == '隐藏') {
      img.style.display = 'none';
      btn.innerHTML = '显示'
    } else {
      img.style.display = 'block';
      btn.innerHTML = '隐藏';
    }
  }
</script>

</html>